package com.uenpay.im.ui.old.activity.crowdfund;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 发起众筹（江湖救急）
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class CreateCrowdfundInvokItem extends HttpInvokeItem {

	public class CreateCrowdfundInvokItemResult {
		public int status;
		public String msg;
		public String amount;
		public String crowdFundId;
	}

	public CreateCrowdfundInvokItemResult getOutput() {
		return (CreateCrowdfundInvokItemResult) GetResultObject();
	}

	/**
	 * 发起众筹（江湖救急）
	 * 
	 * @param chatid
	 * @param amount
	 * @param memo
	 */
	public CreateCrowdfundInvokItem(String chatid, String amount, String memo) {
		String url = APIConfiguration.getBaseUrl()
				+ "/Purse/Crowdfund/createCrowdfund?amount=" + amount
				+ "&chatid=" + chatid + "&memo=" + memo + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		CreateCrowdfundInvokItemResult result = new CreateCrowdfundInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonData = json.optJSONObject("data");
			if (jsonData != null) {
				if (jsonData.has("fundid")) {
					result.crowdFundId = jsonData.optString("fundid");
				}
				if (jsonData.has("amount")) {
					result.amount = jsonData.optString("amount");
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
